package cn.hxzy.controller;


import cn.hxzy.domain.Task;
import cn.hxzy.response.R;
import cn.hxzy.service.TaskService;
import io.swagger.models.auth.In;
import org.junit.jupiter.params.ParameterizedTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author niuyi
 * @since 2024-06-22
 */
@RestController
@RequestMapping("/task")
public class TaskController {
    @Autowired
    private TaskService taskService;

    /**
     * 查询当前小节作业
     *
     * @param sectionId
     * @return
     */
    @GetMapping("/selectTaskList")
    public R<List<Task>> selectTaskList(Integer sectionId) {
        List<Task> tasks = taskService.selectTaskList(sectionId);
        System.out.println(tasks);
        if (tasks != null) {
            return R.success(tasks);
        }
        return null;
    }

    /**
     * 搜索框搜索作业名称
     * @param sectionId
     * @param taskName
     * @return
     */
    @GetMapping("/selectTask")
    public R selectTask(Integer sectionId,String taskName){

        return null;
    }


    /**
     * 删除作业
     * @param taskId
     * @return
     */
    @DeleteMapping("/deleteTask")
    public R deleteTask(@RequestParam Integer taskId){
        return R.success("删除成功");
    }

    /**
     * 编辑作业
     * @param taskName
     * @param
     * @return
     */
    @PatchMapping("/updateTask")
    public R updateTask(@RequestParam String taskName,@RequestParam String taskInfo,@RequestParam("file") MultipartFile file){
        return R.success("编辑成功");
    }

    /**
     * 新增作业
     * @param taskName
     * @param taskDetail
     * @return
     */
    @PostMapping("/addTask")
    public R addTask(@RequestParam String taskName,@RequestParam String taskDetail,@RequestParam("file") MultipartFile file){
        return R.success("新增作业成功");
    }

    /**
     * 根据课程获取作业
     * @param courseId
     * @return
     */
    @GetMapping("/getTaskByCourseId")
    public R getTaskByCourseId(@RequestParam("courseId") Integer courseId){
        List<Task> tasks = taskService.selectTaskByCourseId(courseId);
        return R.success(tasks);
    }



}

